/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.component.gateway.core;

import com.google.common.collect.Maps;
import info.peigen.hotpot.component.gateway.core.http.HttpClient;
import info.peigen.hotpot.component.gateway.core.http.enums.HttpType;
import info.peigen.hotpot.component.gateway.core.sign.SignUtil;
import info.peigen.hotpot.component.gateway.core.sign.enums.SignType;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.Solon;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Init;
import org.noear.solon.core.AppContext;

import java.util.List;
import java.util.Map;

/**
 * <b>(AbstractGateway)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2021/4/8
 */
@Slf4j
@Component
public class AbstractGateway {
    private final Map<HttpType, HttpClient> httpClient = Maps.newHashMap();

    private final Map<SignType, SignUtil> signMap = Maps.newHashMap();

    @Init
    public void init() {
        AppContext context = Solon.context();

        //将 HttpClient 缓存
        List<HttpClient> httpClientMap = context.getBeansOfType(HttpClient.class);
        httpClientMap.forEach(value -> httpClient.put(value.httpType(), value));

        //将 signMap 缓存
        List<SignUtil> signUtilMap = context.getBeansOfType(SignUtil.class);
        signUtilMap.forEach(value -> signMap.put(value.signType(), value));
    }
}